<html>
<div id="myheader">
<?php
session_start();
        include "include/top.php";
?>
</div>


<title>OSPMS</title>
<head>

<style type="text/css" media="all">


#mymenu{ MARGIN: 10px 10px 10px 10px;
PADDING:10px 10px 10px 10px;
BORDER-TOP: #CCC 2px solid;
BORDER-RIGHT: #CCC 2px solid;
BORDER-BOTTOM: #CCC 2px solid;
BORDER-LEFT: #CCC 2px solid;
BACKGROUND: url(images/bg_poem.jpg) #FEFEFE no-repeat right bottom;
COLOR: #666;
TEXT-ALIGN: left;
LINE-HEIGHT: 250%; WIDTH:12%; }

#mybody{ POSITION: absolute;
LEFT:300px;
TOP:100px;
WIDTH:900px;
MARGIN: 0px;
PADDING: 0px;
BACKGROUND: #DADADA;
}
#right{ POSITION: absolute;
LEFT:1200px;
TOP:100px;
WIDTH:200px;
MARGIN: 0px;
PADDING: 0px;
BACKGROUND: #FFF; }

 .regtable{width:600px;background:#fff;border-radius:5px;padding-top:30px;padding-bottom:100px}
 .regtable th{font-size:26px;color:#9c9c9c}  <!-- slightly darker than gray -->
 .regtable td{padding: 6px;}
 .regtable td a{color: green;}
 .regtable .lefttd{text-align: right;width:25%;color:gray}
 .regtable .righttd{text-align: left;width:75%}
 .regtable .text{width:58%;border: solid 1px #ddd;height:34px;line-height: 34px;background: #f5f5f5;border-radius:5px} 
<!-- #cmdLogin{width: 200px;height:40px;text-align:center;color:#fff;border:0;background: #e96481;border-radius: 5px;} -->
 #cmdLogin{width: 200px;height:40px;text-align:center;color:#fff;border:0;background: #e96481;border-radius: 5px;} 
a,a:visited {color:#333;text-decoration:none;}
a:hover {color:#f60;}
body,td {font:13px "Geneva","Arial", "Arial", "Helvetica",sans-serif;}
ul,li {margin:0;padding:0;list-style:none;}
h1,h2,h3,h4,h5,h6 {margin:0;padding:0;}
h1 {padding:5px;color:#900;font:16px bold "Geneva","ËÎÌå", "Arial", "Helvetica",sans-serif;}
h1 small {font-size:11px;font-weight:normal;color:#660;}

.TreeWrap {width:160px;}
.MenuBox .titBox a,
.MenuBox .titBox a:visited,
.MenuBox2 .titBox a,
.MenuBox2 .titBox a:visited {margin-left:2px;padding-left:3px;color:#003;font-size:12px;display:block;}
.MenuBox .titBox h3 a {background:url(images/ico_folder_open.gif) no-repeat 0 40%;}
.MenuBox .titBox h3.Fst a {background:url(images/ico_folder_open_fst.gif) no-repeat 0 40%;}
.MenuBox .titBox h3.Lst a {background:url(images/ico_folder_open_lst.gif) no-repeat 0 40%;}
.MenuBox2 .titBox h3 a {background:url(images/ico_folder.gif) no-repeat 0 40%;}
.MenuBox2 .titBox h3.Fst a {background:url(images/ico_folder_fst.gif) no-repeat 0 40%;}
.MenuBox2 .titBox h3.Lst a {line-height:250%;background:url(images/icon_exit.gif) no-repeat 0 0;}
.MenuBox2 .txtBox {display:none;}
.MenuBox .txtBox ul li {padding-left:20px;line-height:150%;}
.MenuBox .txtBox .num {color:#e00;}
.MenuBox .txtBox ul {background:url(images/line_y.gif) repeat-y 16px 0;}
.MenuBox .txtBox ul li {background:url(images/t.gif) no-repeat 28px 50%;}
.MenuBox .txtBox ul li.Lst {background:url(images/t_lst.gif) no-repeat 28px 50%;}
</style>


<script type="text/javascript">
<!--
 function ExChgClsName(Obj,NameA,NameB){
  var Obj=document.getElementById(Obj)?document.getElementById(Obj):Obj;
  Obj.className=Obj.className==NameA?NameB:NameA;
 }
 function showMenu(iNo){
 ExChgClsName("Menu_"+iNo,"MenuBox","MenuBox2");
 }
-->
</script>
</head>


<div id="mymajorbody">

<div id="mymenu">
<body>

<div class="TreeWrap">
<div class="MenuBox" id="Menu_0">
<div class="titBox"><h3 class="Fst"><a href="javascript:showMenu(0);">Setting</a></h3></div>
<div class="txtBox">
 <ul>
  <li><a href="/OSPMS/User.php">User</a></li>
  <li><a href="/OSPMS/Privilege.php">Privilege</a></li>
  <li><a href="/OSPMS/Project.php">Project</a></li>
  <li class="Lst"><a href="/OSPMS/Study.php">Study</a></li>
 </ul>
</div>
</div><!--MenuBox-->
<div class="MenuBox2" id="Menu_1">
<div class="titBox"><h3><a href="javascript:showMenu(1);">Project</a></h3></div>
<div class="txtBox">
 <ul>
  <li><a href="/OSPMS/ShowProjects.php">Show</a></li>
  <li><a href="/OSPMS/Upload_Project.php">Upload</a></li>
  <li class="Lst"><a href="#">J</a></li>
 </ul>
</div>
</div><!--MenuBox-->
<div class="MenuBox2" id="Menu_2">
<div class="titBox"><h3><a href="javascript:showMenu(2);">Program</a></h3></div>
<div class="txtBox">
 <ul>
  <li><a href="#">Todo</a></li>
  <li class="Lst"><a href="#">M</a></li>
 </ul>
</div>
</div><!--MenuBox-->
<div class="MenuBox2" id="Menu_3">
<div class="titBox"><h3><a href="javascript:showMenu(3);">My Document</a></h3></div>
<div class="txtBox">
 <ul>
  <li><a href="#">Todo</a></li>
  <li class="Lst"><a href="#">R</a></li>
 </ul>
</div>
</div><!--MenuBox-->
<div class="MenuBox" id="Menu_0">
<div class="titBox"><h3 class="Fst"><a href="javascript:showMenu(0);">Admin</a></h3></div>
<div class="txtBox">
 <ul>
  <li><a href="#">Audit Log</a></li>
  <li class="Lst"><a href="#">Sign-in Log</a></li>
 </ul>
</div>
</div>


</div>

<div id="mybody">


<!--
<form method="post" action="<?php $_PHP_SELF ?>">
<table class="mytable regtable">
    <tr>
      <th></th>
      <th class="righttd">Project Settings</th>

    </tr>
    <tr>
      <td class="lefttd">cust_id:</td>
      <td class="righttd"><input type="text" name="cust_id" class="text"/></td>
    </tr>
    <tr>
      <td class="lefttd">Input1:</td>
      <td class="righttd"><input type="text" name="Input1" class="text"/></td>
    </tr>
    <tr>
      <td class="lefttd">Input3:</td>
      <td class="righttd"><input type="text" name="Input3" class="text"/></td>
    </tr>
    <tr>
      <td></td>
      <td class="righttd">
        <input type="submit" value="Submit" name="add" id="cmdLogin"/>
      </td>
    </tr>
</table>
</form>
-->



<?php

echo "<table style='border: solid 1px black;'>";
//echo "<tr><th>Id</th><th>Firstname</th><th>Lastname</th><th>Email</th><th>Reg date</th></tr>"; -

$dbservername = "localhost";
$dbusername = "ospms";
$dbpassword = "ospms";
$dbname = "OSPMS";

session_start();

class TableRows extends RecursiveIteratorIterator {
    function __construct($it) {
        parent::__construct($it, self::LEAVES_ONLY);
    }

    function current() {
        return "<td style='width:150px;border:1px solid black;'>" . parent::current(). "</td>";
    }

    function beginChildren() {
        echo "<tr>";
    }

    function endChildren() {
        echo "</tr>" . "\n";
    }
}


try {
    $conn = new PDO("mysql:host=$dbservername;dbname=$dbname", $dbusername, $dbpassword);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$query = 'SELECT * FROM user_projects';
$select = $conn->query($query);

$total_column = $select->columnCount();
//var_dump($total_column);

for ($counter = 0; $counter <= $total_column; $counter ++) {
    $meta = $select->getColumnMeta($counter);
    $column[] = $meta['name'];
}
//print_r($column);
//

//var_dump($_SESSION);
//var_dump($_REQUEST);
$username = "test1";
$user_id = 1;

//$query = "DESCRIBE user_projects";
//$stmt = $conn->prepare($query);
//$stmt->execute();
//$table_fields = $stmt->fetchAll(PDO::FETCH_COLUMN);
//print_r($table_fields);

//$table_fields = array (
//  0 => 'project_id',
//  1 => 'user_id',
//  2 => 'project_name',
//  3 => 'project_description',
//  4 => 'project_type',
//);
$table_project_fields = array (
  0 => 'project_name',
  1 => 'project_description',
  2 => 'project_type',
);

//  echo '<div id="project_list">';
//	echo "<tr>". " \n";
//for ( $i=0 ; $i<count($table_project_fields); $i++ ) {
//	echo "<td>" ;
//	print_r($table_project_fields[$i]);
//	echo "</td>" ;
//}

//	echo "</tr>". " \n";
//    $query = "SELECT * FROM user_projects where user_id = 1";
//    $query = "SELECT project_id,user_id,project_name,project_description,project_type FROM user_projects where user_id = 1";
    $query = "SELECT project_name,project_description,project_type FROM user_projects where user_id = ". $user_id;
    $stmt = $conn->prepare($query);
    $stmt->execute();
    // set the resulting array to associative
    $result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
$array_project = $stmt->fetchAll();
//var_dump($array_project);

    foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) {
//        echo $v;
    }
//  echo "</div>";
//  echo "<div><tr> &nbsp; </tr></div>";
$table2_study_fields = array (
  0 => 'study_name',
  1 => 'study_description',
  2 => 'study_type',
  3 => 'Upload File to Study',
);

//  echo '<div id="study_list">';
//  echo "<tr>". " \n";
//for ( $i=0 ; $i<count($table2_study_fields); $i++ ) {
//  echo "<td>" ;
//  print_r($table2_fields[$i]);
//  echo "</td>" ;
//}
//  echo "</tr>". " \n";

    $query = "SELECT study_name,study_description,study_type FROM user_studies where user_id = ". $user_id;
    $stmt = $conn->prepare($query);
    $stmt->execute();
    // set the resulting array to associative
    $result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
$array_study = $stmt->fetchAll();
//var_dump($array_study);

    foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) {
//        echo $v;
    }
//  echo "</div>";

    $dsn = null;


  echo '<div id="project_list">';
  echo "<tr>". " \n";
for ( $i=0 ; $i<count($table_project_fields); $i++ ) {
  echo "<td>" ;
  print_r($table_project_fields[$i]);
  echo "</td>" ;
}
  echo "</tr>". " \n";
  
//var_dump($array_project);
foreach ($array_project as $key => $value) {
  echo "<tr>". " \n";
  $sub_prj = $value;
  foreach ($sub_prj as $sub_key => $sub_value )
  {
      echo "<td>";
#      var_dump($sub_value);
      print_r($sub_value);
      echo "</td>";
  }
  echo "</tr>". " \n";
  if ( $key == 'test1' )
  {
//# check method 1
//    echo "\n</tr>\n";
//    echo "<tr>  <td>1</td><td>2</td><td>3</td>\n";

//# check method 2
//	var_dump($array_study);

// method 3
	echo "<div>";
        echo "<tr>\n";
        foreach($array_study as $substudy => $substudy_item)
        {
//              print_r($substudy_item);
              echo "<tr>\n";
              foreach($substudy_item as $subsubitm => $subsubvalue )
              {
                  echo "<td>\n";
                  print_r($subsubvalue);
                  echo "</td>\n";
              }
              echo "<td class="righttd">  
                 input type="submit" value="Upload" name="add" id="cmdLogin"/>	
		</td>\n";
              echo "</tr>\n";
        }
        echo "</tr>\n";
	echo "</div>";

  }
}
  echo "</div>";


  echo '<div id="study_list">';
  echo "<tr>". " \n";
for ( $j=0 ; $j<count($table2_study_fields); $j++ ) {
  echo "<td>" ;
  print_r($table2_fields[$j]);
  echo "</td>" ;
}
  echo "</tr>". " \n";
  echo "</div>";





//var_dump($array_project);
//var_dump($array_study);


} // try
catch(PDOException $e)
{
    echo "Error: " . $e->getMessage();
} // try - catch



$conn = null;
echo "</table>";
?> 



</div>
</div>



<div>

  <link rel="stylesheet" href="style/ospms.css" type="text/css">
  <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
  <script language="JavaScript" type="text/javascript" src="Project_Library_files/jquery.js"></script>
  <script language="JavaScript" type="text/javascript" src="Project_Library_files/ospms.js"></script>



<table id="headerHolder" cellpadding="0" cellspacing="0"><tbody><tr><td>
<div id="header">
 <ul>
  <li><a href="./index.html" title="programs">Programs</a></li>
  <li><a href="./index.html" title="projects">Projects</a></li>
  <li><a href="utilities.html" title="studies">Studies</a></li>
  <li><a href="./index.html" title="uploaded">Uploaded_Files</a></li>
 </ul>
</div>
</td></tr></tbody></table>




<div class="content" style="clear:both;">

&nbsp;
</td></tr>


<tr valign="top"><td class="container" align="left" valign="top">
<p>

</p><form name="options" action="">
 <label for="showComments"><input id="showComments" type="checkbox">Upload File</label>
<!-- <label for="showLegend"><input checked="checked" id="showLegend" type="checkbox">Legend</label> -->
</form>

</td></tr></tbody></table>
<div class="indent">
<!-- <b>contains __5__ studies</b>  sort:<a name="columns"></a> -->

<!--

<table id="columns" class="dataTable" rules="groups" border="1">
<colgroup>
</colgroup><colgroup>
</colgroup><colgroup>
</colgroup><colgroup>
</colgroup><colgroup>
</colgroup><colgroup>
</colgroup><colgroup>
</colgroup><colgroup class="comment">
</colgroup><thead align="left">
<tr>
  <th class="sortedByColumn">Table</th>
  <th class="notSortedByColumn"><a href="#"><span class="notSortedByColumn">Study_Name</span></a></th>
  <th class="notSortedByColumn"><a href="#"><span class="notSortedByColumn">Study_Type</span></a></th>
  <th class="notSortedByColumn"><a href="#"><span class="notSortedByColumn">Number_of_Files</span></a></th>
  <th title="Are nulls allowed?" class="notSortedByColumn"><a href="#"><span class="notSortedByColumn">Revision</span></a></th>
  <th title="Is column automatically updated?" class="notSortedByColumn"><a href="#"><span class="notSortedByColumn">Date</span></a></th>
  <th title="Default value" class="notSortedByColumn"><a href="#"><span class="notSortedByColumn">Description</span></a></th>
  <th title="Comments" class="comment"><span class="notSortedByColumn">Upload File</span></th>
</tr>
</thead>
<tbody valign="top">
<tr class="even">
 <td class="detail"><a href="#">Study #1</a></td>
 <td class="detail">Study #1</td>
 <td class="detail">study_type</td>
 <td class="detail" align="right">50</td>
 <td class="detail" align="center"></td>
 <td class="detail" align="center"></td>
 <td class="detail"></td>
 <td class="comment detail">Upload_Button</td>
</tr>
<tr class="even">
 <td class="detail"><a href="#">Study #2</a></td>
 <td class="detail">state</td>
 <td class="detail">another_type</td>
 <td class="detail" align="right">2</td>
 <td class="detail" align="center"></td>
 <td class="detail" align="center"></td>
 <td class="detail"></td>
 <td class="comment detail">Upload_Button</td>
</tr>

</tbody></table>

-->


</div>
</div>


</div>  <!-- new section -->








<div id="myfooter">
<?php
        include "include/bottom.php"
?>
</div>
